//
//  SLCAReplicatorLayerController.m
//  Objective-C
//
//  Created by S_Line on 2018/6/29.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLCAReplicatorLayerController.h"

#import "ReflectionView.h"

static CGFloat const bianchang = 30;

@interface SLCAReplicatorLayerController ()

@property (nonatomic, weak) UIView *containerView;

@end

@implementation SLCAReplicatorLayerController

- (void)initNavBar {
    self.navTitle = @"CAReplicatorLayer";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavBar];
    
    [self initView];
}

- (void)initView {
    UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, bianchang, bianchang)];
    containerView.backgroundColor = [UIColor grayColor];
    self.containerView = containerView;
    [self.view addSubview:containerView];
    
    // create a replicator layer and add it to our view
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.frame = self.containerView.bounds;
    [self.containerView.layer addSublayer:replicatorLayer];
    
    // configure the replicator
    replicatorLayer.instanceCount = 10;
    
    // apply a transform for each instance
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DTranslate(transform, 0, bianchang * 2.0, 0);
    transform = CATransform3DRotate(transform, M_PI / 5.0, 0, 0, 1);
    transform = CATransform3DTranslate(transform, 0, -bianchang * 2.0, 0);
    replicatorLayer.instanceTransform = transform;
    
    // apply a color shift for each instance
    replicatorLayer.instanceBlueOffset = -0.05;
    replicatorLayer.instanceGreenOffset = -0.1;
    
    // create a sublayer and place it inside the replicator
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(bianchang * 2.0, bianchang * 2.0, bianchang * 2.0, bianchang * 2.0);
    layer.backgroundColor = [UIColor blueColor].CGColor;
    [replicatorLayer addSublayer:layer];
    
    ReflectionView *reflectionView = [[ReflectionView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
    [self.view addSubview:reflectionView];
    
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 100, 30)];
    textLabel.text = @"可结案了空间发的垃圾水电费";
    textLabel.textColor = [UIColor blueColor];
    [reflectionView addSubview:textLabel];
}

@end
